﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using ChinaGS.Lian.ModuleRemoting;

public partial class recharge_area_fill_telecom : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SysCommon.checkUserLogin();

        if (!IsPostBack)
        {
            String AccpetType = Request["HidAccpetType"];
            String Charge = Request["HidCharge"];
            String ReceiPay = Request["HidReceiPay"];
            String cusNo = Request["HidcusNo"];
            String AcctId = Request["HidAcctId"];

            if (Request["HidAccpetType"] != null)
            {
                if (AccpetType.Equals("1"))//后付费
                {
                    //显示查询结果     
                    this.LabChargeName.Text = "本期账单";
                    this.LabCharge.Text = ReceiPay;
                }
                else
                { //预付费2,3

                    //显示查询结果            
                    this.LabChargeName.Text = "账户余额";
                    this.LabCharge.Text = Charge;
                }

                HidAccpetType.Value = AccpetType;
                HidCharge.Value = Charge;
                HidReceiPay.Value = ReceiPay;
                HidcusNo.Value = cusNo;
                HidAcctId.Value = AcctId;

                PanPay.Visible = true;

            }
            else
            {
                PanPay.Visible = false;
                this.LabMessage.Text = "操作失败，请重试！";

            }
        }
    }

    protected void NextStep_Click(object sender, EventArgs e)
    {         
        Double Charge = System.Convert.ToDouble(HidCharge.Value);
        String cusNo = HidcusNo.Value;
        String AccpetType = HidAccpetType.Value;
        Double ReceiPay = System.Convert.ToDouble(HidReceiPay.Value);
        String AcctId = HidAcctId.Value;


        //充值前操作            
            int user_paid_id = DataBaseOperate_SQLServer.execPPaidAtonce(Session["user_id"].ToString(), "4".ToString(), HidcusNo.Value, 
                TexPayMoney.Text, TexPayMoney.Text, "0".ToString(), "0".ToString(), "0".ToString(), System.DateTime.Now.ToString(), "none".ToString());

            if (user_paid_id < 0)
            {
                LabMessage.Text = "操作失败！原因是：" + RemotingClass.alertExecErroeResult(user_paid_id).ToString() + "，请重试";
                PanPay.Visible = false;
            }
            else {
                if (AccpetType == "1")
                {
                    if (ReceiPay == 0)
                    {
                        AccpetType = "2";
                    }
                }

                TeleComPackage tcp = RemotingClass.teleComPayMoney(AcctId, cusNo, AccpetType, System.Convert.ToDouble(TexPayMoney.Text));
                //测试使用           
                /*TeleComPackage tcp = new TeleComPackage();
                tcp.Status = true;//	收发状态	标示该交易是否成功
                tcp.SerialNo = "1234567890";//	交易流水号	缴费时返回
                tcp.Message = "success";//返回消息	根据状态码不同为不同消息
                tcp.StatusNo = "00";//状态码	见状态码定义
                tcp.AccpetType = "1";//受理类型
                tcp.AccpetTypeCN = "后付费";//	受累类型中文
                tcp.ItemNo = "123456789";//	合同号
                tcp.CusNo = cusNo;//客户号码
                tcp.CusName = "DenverYee";//客户名称
                tcp.Charge = 0;//账户余额
                tcp.RealPay = 0;//实收金额
                tcp.ReceiPay = 0;//应收金额
                tcp.PayDate = DateTime.Now.ToString("yyyy年MM月dd日");//付款日期
                tcp.isDeaulting = false;//是否欠费*/


                if (tcp.Status)
                {
                    //充值成功操作                
                    DataBaseOperate_SQLServer.execPPaidSetStatus(user_paid_id.ToString(), tcp.SerialNo,
                        tcp.CusNo, tcp.Message, "1".ToString(), SysCommon.getClientIP(), "0".ToString());
                    Response.Redirect("paysuccess_telecom.aspx?HidRealPay=" + tcp.RealPay
                                        + "&HidCharge=" + tcp.Charge.ToString()
                                        + "&HidReceiPay=" + tcp.ReceiPay.ToString()
                                        + "&HidPayDate=" + tcp.PayDate
                                        + "&HidcusNo=" + tcp.CusNo);
                }
                else
                {
                    DataBaseOperate_SQLServer.execPPaidSetStatus(user_paid_id.ToString(), tcp.SerialNo,
                        tcp.CusNo, tcp.Message, "2".ToString(), SysCommon.getClientIP(), "0".ToString());
                    LabMessage.Text = "操作失败！原因是：" + tcp.Message + "，请稍后重试";
                    PanPay.Visible = false;
                }
            
            }



        
    }      


}
